package com.u.social.article.controller;


import com.u.social.article.entity.Topics;
import com.u.social.article.service.ITopicsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Alex Wu
 * @since 2025-01-23
 */
@RestController
@RequestMapping("/topics")
public class TopicsController {

    @Autowired
    private ITopicsService topicsService;

    @PostMapping("/create")
    public String create(@RequestBody Topics topic) {
        topicsService.save(topic);
        return "Topic created successfully";
    }

    @GetMapping("/{id}")
    public Topics getById(@PathVariable String id) {
        return topicsService.getById(id);
    }



    @PutMapping("/update")
    public String update(@RequestBody Topics topic) {
        topicsService.updateById(topic);
        return "Topic updated successfully";
    }

    @DeleteMapping("/delete/{id}")
    public String delete(@PathVariable String id) {
        topicsService.removeById(id);
        return "Topic deleted successfully";
    }
}

